package com.dhcc.sds.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dhcc.cdc.sys.dao.CdcProductMapper;
import com.dhcc.cdc.sys.dao.DictionaryMapper;
import com.dhcc.cdc.sys.dao.DictypeMapper;
import com.dhcc.cdc.sys.entity.CdcProductEntity;
import com.dhcc.cdc.sys.entity.DictionaryEntity;
import com.dhcc.cdc.sys.entity.DictypeEntity;
import com.dhcc.cdc.sys.service.IDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import com.dhcc.sds.base.dao.SdsExpressMapper;
import com.dhcc.sds.base.service.ISdsExpressService;
import com.dhcc.sds.base.entity.SdsExpressEntity;

/**
 * 产品函数库表数据服务层接口
 * 
 * @ClassName: SdsExpressServiceImpl
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:10:53
 */
@Service("sdsExpressService")
public class SdsExpressServiceImpl extends BaseServiceImpl<SdsExpressMapper, SdsExpressEntity> implements ISdsExpressService {

	@Autowired
	private CdcProductMapper productMapper;
	@Autowired
	private DictypeMapper dictypeMapper;
	@Autowired
	private DictionaryMapper dictionaryMapper;

	@Override
	public List<SdsExpressEntity> page(Page<SdsExpressEntity> page, Map<String, Object> map) {
		return this.baseMapper.page(page, map);
	}
	@Override
	public List<SdsExpressEntity> list(Map<String, Object> map) {
		return this.baseMapper.list(map);
	}
	@Override
	public Map<String, Object> findExpsByCode(String code){
		CdcProductEntity productEntity = new CdcProductEntity();
		productEntity.setCode("SDS");
		productEntity = productMapper.selectOne(productEntity);

		DictypeEntity dicType = new DictypeEntity();
		dicType.setProductId(productEntity.getId());
		dicType.setCode("SDExpType");
		dicType = dictypeMapper.selectOne(dicType);

		Map<String,Object> map = new HashMap<String,Object>();
		map.put("dictypeId", dicType.getId());
		List<DictionaryEntity> dicList =  dictionaryMapper.list(map);
		for (DictionaryEntity dict : dicList) {
			if (code.equals(dict.getCode())) {
				map.clear();
				map.put("expType", dict.getId());
				break;
			}
		}
		List<SdsExpressEntity> QcRuleExpList = this.baseMapper.list(map);
		Map<String, Object> expMap = new HashMap<>();
		for(SdsExpressEntity exp : QcRuleExpList){
			expMap.put(exp.getId().toString(), exp.getExpDesc());
		}
		return expMap;
	}
}